const APIKEY = "1f2e3289eb73c053ad6dd0cb9329f915"
var app = getApp()
Page({
  data: {
    pinyinText: '',
  },
  // 事件处理函数
  onInput: function (e) {
    var that = this
    var char = e.detail.value
    wx.request({
      url: 'https://api.tianapi.com/txapi/xhzd/index?key=' + APIKEY + '&word=' + char,
      success: function (res) {
        if (res.data.code == 200) {
          //console.log(res.data.newslist[0].content)
          let datas = res.data.newslist[0].content
          let reg = RegExp(/<br>/)
          while (reg.exec(datas)) {
            datas = datas.replace('<br>', '\n')
          }
          //console.log(datas)
          that.setData({
            pinyinText: datas
          })
        } else {
          that.setData({
            pinyinText: res.data.msg
          })
        }
      },
      fail: function (err) {
        console.log(err)
      }
    })
  },
})